package com.Pawtrack.web.controller.info;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.Pawtrack.common.annotation.Log;
import com.Pawtrack.common.annotation.DataScope;
import com.Pawtrack.common.core.controller.BaseController;
import com.Pawtrack.common.core.domain.AjaxResult;
import com.Pawtrack.common.enums.BusinessType;
import com.Pawtrack.info.domain.PetLocation;
import com.Pawtrack.info.service.IPetLocationService;
import com.Pawtrack.common.utils.poi.ExcelUtil;
import com.Pawtrack.common.core.page.TableDataInfo;
import com.Pawtrack.common.utils.SecurityUtils;

/**
 * 宠物定位Controller
 * 
 * @author ruoyi
 * @date 2025-08-14
 */
@RestController
@RequestMapping("/system/location")
public class PetLocationController extends BaseController
{
    @Autowired
    private IPetLocationService petLocationService;

    /**
     * 查询宠物定位列表
     */
    @GetMapping("/list")
    @DataScope(deptAlias = "p", userAlias = "p")
    public TableDataInfo list(PetLocation petLocation)
    {
        startPage();
        List<PetLocation> list = petLocationService.selectPetLocationList(petLocation);
        return getDataTable(list);
    }

    /**
     * 导出宠物定位列表
     */
    @Log(title = "宠物定位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PetLocation petLocation)
    {
        List<PetLocation> list = petLocationService.selectPetLocationList(petLocation);
        ExcelUtil<PetLocation> util = new ExcelUtil<PetLocation>(PetLocation.class);
        util.exportExcel(response, list, "宠物定位数据");
    }

    /**
     * 获取宠物定位详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(petLocationService.selectPetLocationById(id));
    }

    /**
     * 新增宠物定位
     */
    @Log(title = "宠物定位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PetLocation petLocation)
    {
        // 设置创建人为当前用户ID
        petLocation.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
        return toAjax(petLocationService.insertPetLocation(petLocation));
    }

    /**
     * 修改宠物定位
     */
    @Log(title = "宠物定位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PetLocation petLocation)
    {
        // 设置更新人为当前用户ID
        petLocation.setUpdateBy(String.valueOf(SecurityUtils.getUserId()));
        return toAjax(petLocationService.updatePetLocation(petLocation));
    }

    /**
     * 删除宠物定位
     */
    @Log(title = "宠物定位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(petLocationService.deletePetLocationByIds(ids));
    }
}
